<%@ page import="com.wuming.house.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/3/20
  Time: 18:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>资讯管理</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css" media="all"/>
    <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">-->
    <!--<link rel="stylesheet" href="bootstrap-select-master/dist/css/bootstrap-select.css">-->
    <script type="text/javascript" src="${allServerPath}static/layui/layui/layui.js"></script>
</head>
<body style="background-color: #f0f2f5;" class="childrenBody">
<div class="layui-fluid wuli-main">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>资讯管理</legend>
        </fieldset>
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">标题</label>

                    <div class="layui-input-inline">
                        <input type="text" id="title" name="title" lay-verify="number" autocomplete="off"
                               class="layui-input" value="${information['title']}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">资讯路径</label>

                    <div class="layui-input-inline">
                        <input type="text" id="url" name="url" lay-verify="number" autocomplete="off"
                               class="layui-input" value="${information['url']}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">资讯来源</label>

                    <div class="layui-input-inline">
                        <input type="text" id="source" name="source" lay-verify="number"
                               autocomplete="off"
                               class="layui-input" value="${information['source']}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 100px">资讯图片</label>

                    <div class="layui-upload-list" style="display: inline">
                        <img class="layui-upload-img" id="uploadImage" style="width: 114px;height: 86px;border: 1px dotted #F0F0F0;" src="${allServerPath}/upload/${information.imagePath}">
                        <%--<p id="demoText"></p>--%>
                    </div>
                </div>
            </div>
            <input type="hidden" name="imagePath" id="imagePath" value="${information.imagePath}">
        </form>
        <div class="layui-inline layui-word-aux">
            注意:图片不能超过1Mb
        </div>
        <div class="layui-row wuli-button">
            <button type="button" class="layui-btn" id="btnUploadImg">选择图片</button>
            <button class="layui-btn layui-btn-normal" name="saveInformation">保存资讯信息</button>
        </div>
    </div>
</div>

<script>
    layui.use(['layer', 'form', 'laydate', 'jquery','upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , $ = layui.$
            , upload = layui.upload;

        //普通图片上传
        upload.render({
            elem: '#btnUploadImg'
            ,url: '${allServerPath}web/information/uploadImg.htmls'
            ,size : 1024
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadImage').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                if (res.success) {
                    $('#imagePath').val(res.data)
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

        $("button[name='saveInformation']").on('click', function () {
            $.ajax({
                type: "post",
                data: {
                    id: '${information.id}',
                    title: $("#title").val(),
                    url: $("#url").val(),
                    source: $("#source").val(),
                    imagePath:$("#imagePath").val()
                },
                url: '${allServerPath}web/information/edit.htmls?t=<%=System.currentTimeMillis()%>',
                success: function (obj) {
                    if (obj.success) {
                        // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        // parent.layer.close(index); //再执行关闭
                        layer.msg("保存成功");

                    }
                }
            });
        });
    });
</script>
</body>
</html>
